/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import Beans.UserInterest;
import datas.UserInterestMapper;
import java.util.List;
import org.apache.ibatis.session.SqlSession;

/**

 @author jtanguay
 */
public class UserInterestDao {

  //Recuperer les interet pour un user
  public static List<UserInterest> getAllInterestForUser(int idUser) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {
      UserInterestMapper mapper = session.getMapper(UserInterestMapper.class);
      List<UserInterest> userInterestList = mapper.getallInterestForUser(idUser);

      return userInterestList;
    } finally {
      MyBatisManager.closeConnexion();
    }
  }

  //Inserer un interet pour un user
  public static int insertAnInterest(int idUser, int idInterest) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {
      UserInterestMapper mapper = session.getMapper(UserInterestMapper.class);
      int interest = mapper.insertInterest(idUser, idInterest);

      session.commit();

      return interest;
    } finally {
      MyBatisManager.closeConnexion();
    }
  }

  //Delete un interet pour un user
  public static int deleteUserInterest(int idUser, int idInterest) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {
      UserInterestMapper mapper = session.getMapper(UserInterestMapper.class);
      int retour = mapper.deleteInterest(idUser, idInterest);

      session.commit();

      return retour;
    } finally {
      MyBatisManager.closeConnexion();
    }
  }
}
